package com.example.xui_study;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.xuexiang.xui.widget.progress.CircleProgressView;
import com.xuexiang.xui.widget.progress.HorizontalProgressView;
import com.xuexiang.xui.widget.toast.XToast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ProgressActivity extends BaseActivity implements HorizontalProgressView.HorizontalProgressUpdateListener {

    @BindView(R.id.hpv_math)
    HorizontalProgressView hpvMath;
    @BindView(R.id.progress_text_math)
    TextView progressTextMath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);
        ButterKnife.bind(this);

        hpvMath.setProgressViewUpdateListener(this);

        hpvMath.setEndProgress(100);
        hpvMath.startProgressAnimation();
    }


    @Override
    public void onHorizontalProgressStart(View view) {
        XToast.info(ProgressActivity.this,"进度条开始").show();
    }

    @Override
    public void onHorizontalProgressUpdate(View view, float progress) {
        int progressInt = (int) progress;
        switch (view.getId()) {
            case R.id.hpv_math:
                progressTextMath.setText(progressInt + "%");
                break;
            default:
                break;
        }
    }

    @Override
    public void onHorizontalProgressFinished(View view) {
        XToast.success(ProgressActivity.this,"进度已经全部加载完成!").show();
    }


    @OnClick({R.id.bt_back})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_back:
                onBackPressed();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {

        hpvMath.stopProgressAnimation();
        hpvMath.setProgressViewUpdateListener(null);

        super.onDestroy();
    }
}
